package com.kk.xhr.model.service.impl;

import com.kk.xhr.model.dao.NoticeDynamicSqlSupport;
import com.kk.xhr.model.dao.NoticeMapper;
import com.kk.xhr.model.entity.Notice;
import com.kk.xhr.model.service.INoticeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 通知服务接口实现
 *
 * @author kkmystery
 * @version 1.0 2021/3/20
 * @since 1.0.0
 */
@Repository
@RequiredArgsConstructor
public class NoticeServiceImpl implements INoticeService {
    private final NoticeMapper noticeMapper;

    @Override
    public List<Notice> query() {
        return noticeMapper.select(dsl -> dsl
            .orderBy(NoticeDynamicSqlSupport.updated.descending()));
    }

    @Override
    public long add(Notice notice) {
        noticeMapper.insertSelective(notice);
        return notice.getId();
    }

    @Override
    public boolean modify(Notice notice) {
        if (null == notice.getId()) {
            return false;
        }
        return 1 == noticeMapper.updateByPrimaryKeySelective(notice);
    }

    @Override
    public boolean remove(long id) {
        return 1 == noticeMapper.deleteByPrimaryKey(id);
    }
}
